package UILayer;
import java.util.*;
import CtrlLayer.*;
import ModelLayer.*;

public class ManagersUI
{
    ManagerController managerController;
    public ManagersUI(){
        managerController = new ManagerController();
    }

    public void managersMenuStart(){
        boolean exit=false;
        while (!exit){
            int choice = writeManagersMenu();
            switch(choice){
                case 1:
                startCreateManager();
                break;
                case 2:
                startFindManager();
                break;
                case 3:
                startUpdateManager();
                break;
                case 4:
                startDeleteManager();
                break;
                case 0:
                exit = true;
                break;
            }
        }
    }

    private int writeManagersMenu(){    
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** Managers Menu ***");
        System.out.println(" (1) Add manager");
        System.out.println(" (2) Show manager");
        System.out.println(" (3) Update manager	");
        System.out.println(" (4) Delete manager	");
        System.out.println(" (0) Back");
        System.out.print("\n Make your choice: ");
        int choice = keyboard.nextInt();
        return choice;
    }

    private void startCreateManager(){
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Input id");
        int id = Integer.parseInt(keyboard.nextLine());
        System.out.println("Input name");
        String name =  keyboard.nextLine();
        System.out.println("Input email");
        String email = keyboard.nextLine();
        System.out.println("Input phoneNumber");
        String phoneNumber = keyboard.nextLine();
        System.out.println("Input department");
        String department = keyboard.nextLine();
        System.out.println("Input password");
        String password = keyboard.nextLine();
        
        if(managerController.createManager(id, name, email, phoneNumber, department, password)) {
            System.out.println("Employee with id " + id + " has been added!");
        } else {
            System.out.println("Employee with id " + id + " already exists!");
        }
        
        pause();
    }

    private void startFindManager(){
        Scanner keyboard = new Scanner(System.in);
        try{
            System.out.println("Input id");
            int id = Integer.parseInt(keyboard.nextLine());
            Manager p = managerController.findManager(id);
            System.out.println("Id:");
            System.out.println(p.getId());
            System.out.println("Name:");
            System.out.println(p.getName());
            System.out.println("email:");
            System.out.println(p.getEmail());
            System.out.println("phoneNumber:");
            System.out.println(p.getPhoneNumber());
            System.out.println("department:");
            System.out.println(p.getDepartment());
            System.out.println("password:");
            System.out.println(p.getPassword());
        }catch(Exception e){
            System.out.println("Manager not found!");
        }
        pause();
    }

    private void startUpdateManager(){
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Input id");
        int id = Integer.parseInt(keyboard.nextLine());
        System.out.println("Input name");
        String name = keyboard.nextLine();
        System.out.println("Input address");
        String address = keyboard.nextLine();
        System.out.println("Input email");
        String email = keyboard.nextLine();
        System.out.println("Input phoneNumber");
        String phoneNumber = keyboard.nextLine();
        System.out.println("Input department");
        String department = keyboard.nextLine();
        System.out.println("Input password");
        String password = keyboard.nextLine();

        managerController.updateManager(id, name, email, phoneNumber, department, password);
    }

    private void startDeleteManager(){
        try{
            Scanner keyboard = new Scanner(System.in);
            System.out.println("Input id");
            int id = Integer.parseInt(keyboard.nextLine());
            managerController.deleteManager(id);
        }catch(Exception e){
            System.out.println("Input name doesn't exist");
        }
        pause();
    }

    private void pause(){
        Scanner keyboard = new Scanner(System.in);
        String vent = keyboard.nextLine();
    }
}
